<?php
	
class Admin_Model_ProductGroup extends Admin_Model_Db_ProductGroup
{
	//
	public function fetchGroups($product_group_parent_group_code = "", $prevent_id = '', $where_str = "", $order_str = "product_group_order ASC")
	{
		$where = " 1 ";
		$where .= "  AND product_group_parent_group_code = '$product_group_parent_group_code' ";
		if ($prevent_id != "")
			$where .= " AND product_group_id NOT IN ({$prevent_id}) ";
		$where .= $where_str;
		$groups = $this->fetchAllBase ( $where, $order_str );
		$result_groups = array();
		foreach ( $groups as $group )
		{ 
			$temp_groups = $this->fetchGroups ( $group->product_group_code, $prevent_id, $where_str, $order_str );			
			$group->m_Array ['child'] = $temp_groups;
			$result_groups [] = $group;
		}
		return $result_groups;
	}

	//
	public function fetchOptions($groups = array(), $spaceChar = '|&mdash;', $space = 1, &$options = array())
	{
		if (is_array ( $groups ) && (count ( $groups ) > 0))
		{
			foreach ( $groups as $group )
			{
				$temp = '';
				for($i = 0; $i < $space; $i ++)
					$temp .= $spaceChar;
				
				$options [$group->product_group_code] = $temp . $group->product_group_name;
				if (is_array ( $group->m_Array ['child'] ) && (count ( $group->m_Array ['child'] ) > 0))
				{
					$this->fetchOptions ( $group->m_Array ['child'], $spaceChar, $space + 1, $options );
				}
			
			}
		}
		return $options;
	}

	//
	public function fetchObjects($groups = array(), &$object_arr = array())
	{
		if (is_array ( $groups ) && (count ( $groups ) > 0))
		{
			foreach ( $groups as $group )
			{
				$object_arr [] = $group;
				if (is_array ( $group->m_Array ['child'] ) && (count ( $group->m_Array ['child'] ) > 0))
				{
					$this->fetchObjects ( $group->m_Array ['child'], $object_arr );
				}
			}
		}
		return $object_arr;
	}
}